<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 普调函数
    function foo(x,y,z){
      console.log(x,y,z);
    }
    foo(10,20,30) //=>转变成可以f00(x)(y)(z)这样调用的过程就是柯里化
    function foo1(x){
      return function(y){
        return function(z){
          console.log(x,y,z) //使用了闭包
        }
      }
    }
    foo1(10)(20)(30)


    // 柯里化的另外一种写法
    var foo3 = x => y => z => {
      console.log(x+y+z);
    }

    // 自动柯里化函数
    function hyCurry(fn){
      var fnCurry = function(...args){
        if(args.length>=fn.length){
          fn.apply(this,...args)
        }else{
          return function(...newArgs){
            return fnCurry(...args.concat(newArgs))
          }
        }
      }
      return fnCurry
    }
    var fooCurry = hyCurry(foo)
    fooCurry(10)(20)(30)
  </script>
</body>
</html>